import { InputQuestion, QuestionBase, TextQuestion, SelectQuestion, TimeQuestion, TextTable, TableBase } from '@/components/public-template';
import { Api } from '@/config/api/searchManage';
import { DMS_ARCHIVES_FILE_LIST_STATUS } from '@/filters/color';
import { regExp } from '@/utils/regExp';

class IndexService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'filesBoxCode',
        label: '档案编码',
        placeholder: '请输入',
        reg: regExp.strLen20,
        prompt: '输入字符需小于20'
      }),
      new InputQuestion({
        key: 'name',
        label: '文件名称',
        placeholder: '请输入',
        reg: regExp.len100,
        prompt: '输入字符需小于100'
      }),
      new InputQuestion({
        key: 'code',
        label: '文件编码',
        placeholder: '请输入',
        reg: regExp.strLen20,
        prompt: '输入字符需小于20'
      }),
      new SelectQuestion({
        key: 'archivesType',
        label: '档案类型',
        prompt: '请选择',
        value: [],
        type: 'tree',
        state: {
          url: Api.typeTree,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children',
          expandAll: true,
          multiple: true
        }
      }),
      new SelectQuestion({
        key: 'chargeUserId',
        label: '责任者',
        prompt: '请选择',
        type: 'tree',
        value: [],
        state: {
          url: Api.subjectListSimple,
          protType: 'post',
          nameKey: 'nickName',
          multiple: true,
          nameValue: 'id',
          showSearch: true,
          optionFilterProp: 'label'
        }
      }),
      new SelectQuestion({
        key: 'secretLevel',
        label: '保密等级',
        value: [],
        defaultValue: [],
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'SECRET_LEVEL'
        }
      }),
      new SelectQuestion({
        key: 'type',
        label: '载体形式',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_TYPE'
        }
      }),
      new TimeQuestion({
        key: 'startFromDate',
        label: '形成时间',
        state: {
          keySplit: ['startFromDate', 'endFromDate'],
          format: 'YYYY-MM-DD',
          valueFormat: 'YYYY-MM-DD'
        }
      })
    ];
    return questions;
  }

  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'filesBoxCode',
        value: '档案编码'
      }),
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'code',
        value: '文件编码'
      }),
      new TextTable({
        key: 'filesTypeName',
        value: '档案类型'
      }),
      new TextTable({
        key: 'secretLevel',
        value: '保密等级',
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new TextTable({
        key: 'fromDate',
        value: '形成时间'
      }),
      new TextTable({
        key: 'chargeUserName',
        value: '责任者'
      }),
      new TextTable({
        key: 'type',
        value: '载体形式',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_TYPE'
        }
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: {
          fixed: 'right',
          width: 180
        },
        handle: [
          {
            type: 'local',
            text: '预览',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {},
            showKey: [{ key: 'couldPreview', value: true }]
          },
          {
            type: 'local',
            text: '下载',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {},
            showKey: [{ key: 'couldDownload', value: true }]
          }
        ]
      })
    ];
    return tables;
  }

  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '下载',
        type: 'primary',
        class: 'icon-download',
        state: {}
      }),
      new TextTable({
        key: 'local',
        value: '借阅',
        type: 'default',
        state: {}
      })
    ];
    return icons;
  }
}

export default new IndexService();
